package com.example.caimogu.fragmentAdapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.caimogu.bean.Goods;
import com.example.caimogu.businessapp.R;

import java.util.List;

/**
 * Created by Caimogu on 2016/4/21.
 */
public class HistoryAdapter extends BaseAdapter {

    private List<Goods> goodsList;
    private LayoutInflater inflater;

    public HistoryAdapter(List<Goods> goodsList, LayoutInflater inflater) {
        this.goodsList = goodsList;
        this.inflater = inflater;
    }

    @Override
    public int getCount() {
        return goodsList.size();
    }

    @Override
    public Object getItem(int position) {
        return goodsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        //return goodsList.get(position).getId();
        return 1001;
    }

    @Override
    public View getView( final int position, View convertView, ViewGroup parent) {
        convertView =  inflater.inflate(R.layout.historyorder_goodslist,null);

        ImageView snap = (ImageView) convertView.findViewById(R.id.iv_ho_snap__goods);
        TextView title=(TextView)convertView.findViewById(R.id.tv_ho_goods_name);
        TextView content=(TextView)convertView.findViewById(R.id.tv_ho_goods_info);

        title.setText(goodsList.get(position).getName());
        content.setText(goodsList.get(position).getInformation());
        snap.setBackgroundResource(R.drawable.penguin);
//        snap.setImageResource(goodsList.get(position).getPicPath());
//        snap.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Log.i("john", goodsList.get(position).getTitle());
//            }
//        });

        title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("caimogu", "history...goodslist...title");
            }
        });

        return convertView;
    }
}
